package com.knife.cachev2.infra.init;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author lth
 * @created 2025年07月29日 星期二 8:15
 */
@SuppressWarnings("ALL")
@Slf4j
@Component
public class RedisCacheManager implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        // 初始化缓存
        ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext();
        Map<String, RedisCacheInitiator> map = applicationContext.getBeansOfType(RedisCacheInitiator.class);
        for (Map.Entry<String, RedisCacheInitiator> entry : map.entrySet()) {
            RedisCacheInitiator value = entry.getValue();
            value.init();
        }
    }
}
